package uiLayer;

import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;

import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.KeyStroke;

import uiLayer.uiUtilities.AboutDispEasy;

public class UiMain {

	private JFrame frame;
	private UiContentPane contentPane;
		
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					UiMain window = new UiMain();
					window.frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public UiMain() {
		contentPane = new UiContentPane();
		initializeFrame();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initializeFrame() {
		frame = new JFrame();
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setTitle("DispEasy - Disponeringssystem - Blue Water Shipping A/S");
		Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
		int width = 1200;
		int height = 800;
		int X = (screen.width / 2) - (width / 2); // Center horizontally.
		int Y = (screen.height / 2) - (height / 2); // Center vertically.
		frame.setBounds(X, Y, width, height);

		frame.setJMenuBar(menuBar());
		frame.setContentPane(contentPane);
	}
	
	private JMenuBar menuBar() {
		JMenuBar menuBar = new JMenuBar();
		JMenu mnFile = new JMenu("Filer");
		menuBar.add(mnFile);

		JMenu mnNew = new JMenu("Ny");
		mnNew.setMnemonic('n');
		mnFile.add(mnNew);

		JMenuItem mntmBooking = new JMenuItem("Booking");
		mntmBooking.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				contentPane.showCard(UiBooking.getCard1String());
			}
		});
		mntmBooking.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_B, InputEvent.CTRL_MASK | InputEvent.ALT_MASK));
		mnNew.add(mntmBooking);

		JMenuItem mntmTrailer = new JMenuItem("Trailer");
		mntmTrailer.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				contentPane.showCard(UiTrailer.getCard1String());
			}
		});
		mntmTrailer.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_T, InputEvent.CTRL_MASK | InputEvent.ALT_MASK));
		mnNew.add(mntmTrailer);

		JMenuItem mntmChauffr = new JMenuItem("Chauff\u00F8r");
		mntmChauffr.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				contentPane.showCard(UiDriver.getCard1String());
			}
		});
		mntmChauffr.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.CTRL_MASK | InputEvent.ALT_MASK));
		mnNew.add(mntmChauffr);

		JMenuItem mntmKunde = new JMenuItem("Kunde");
		mntmKunde.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				contentPane.showCard(UiCustomer.getCard1String());
			}
		});
		mntmKunde.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_K, InputEvent.CTRL_MASK | InputEvent.ALT_MASK));
		mnNew.add(mntmKunde);

		JMenuItem mntmChartecKode = new JMenuItem("Chartec kode");
		mntmChartecKode.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				contentPane.showCard(UiChartecCode.getCard1String());
			}
		});
		mntmChartecKode.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_H, InputEvent.CTRL_MASK | InputEvent.ALT_MASK));
		mnNew.add(mntmChartecKode);

//		JMenu mnRediger = new JMenu("Rediger");
//		menuBar.add(mnRediger);

		JMenu mnHelp = new JMenu("Hj\u00E6lp");
		menuBar.add(mnHelp);

		JMenuItem mntmWelcome = new JMenuItem("Velkommen!");
		mntmWelcome.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				contentPane.showCard("WelcomeCard");
			}
		});
		mnHelp.add(mntmWelcome);

		JMenuItem mntmAbout = new JMenuItem("Om Dispeasy");
		mntmAbout.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				AboutDispEasy about = new AboutDispEasy(frame);
				about.setVisible(true);
			}
		});
		mnHelp.add(mntmAbout);

		return menuBar;
	}

}
